{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/roph/anaconda3/envs/twec/lib/python3.6/site-packages/ipykernel_launcher.py:27: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n"
     ]
    }
   ],
   "source": [
    "#########################\n",
    "### Import libraries ####\n",
    "#########################\n",
    "\n",
    "from scripts_for_figure_3 import *\n",
    "\n",
    "####################\n",
    "### Do analysis ####\n",
    "####################\n",
    "\n",
    "#get intersection of vocabulary and calculate distances\n",
    "common_vocab = list(set(list(slice_Republican.wv.vocab)).intersection(list(slice_Democrat.wv.vocab)))\n",
    "all_df = pd.DataFrame({\"word\":common_vocab})\n",
    "all_df[\"repub_score\"] = all_df[\"word\"].apply(lambda x: distance_for_pol_hate_repub(x))\n",
    "all_df[\"demo_score\"] = all_df[\"word\"].apply(lambda x: distance_for_pol_hate_demo(x))\n",
    "\n",
    "#sort and extract top 70\n",
    "repub_df = all_df.sort_values(\"repub_score\", ascending = False).head(70)\n",
    "demo_df = all_df.sort_values(\"demo_score\", ascending = False).head(70)\n",
    "\n",
    "#difference\n",
    "different = set(repub_df[\"word\"]).difference(demo_df[\"word\"])\n",
    "different2 = set(demo_df[\"word\"]).difference(repub_df[\"word\"])\n",
    "\n",
    "#extract top different across models and save\n",
    "all_df_top_70 = all_df[all_df[\"word\"].isin(list(different2)+list(different))]\n",
    "all_df_top_70[\"ideo\"] = np.where(all_df_top_70[\"word\"].isin(list(different)), \"Republican\", \"Democrat\")\n",
    "all_df_top_70.to_csv(\"top_70_id.csv\")\n",
    "\n",
    "\n",
    "#plot results\n",
    "repub_demo_plot(file = \"word_vectors_repub_demo.png\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "twec",
   "language": "python",
   "name": "twec"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
